//
// Created by weslywang on 2020/5/30.
//

#include "../common/common.h"

int longestConsecutive(vector<int> &nums) {
    map<int, bool> hash;
    for (int val: nums) hash[val] = true;
    int Max = 0;
    for (int val: nums) {
        int len = 1, tem = val + 1;
        while (hash.count(tem)) {
            hash.erase(tem);
            len++, tem++;
        }
        tem = val - 1;
        while (hash.count(tem)) {
            hash.erase(tem);
            len++, tem--;
        }
        Max = max(len, Max);
    }
    return Max;
}

int main() {
    struct timeval start;
    struct timeval end;
    unsigned long timer;

    Common common;
    int a[] = {1, 2, 3, 4, 5};
    vector<vector<int>> numList = common.loadData();
    for (int i = 0; i < numList.size(); i++) {
        gettimeofday(&start, NULL);

        cout << (longestConsecutive(numList[i])) << endl;

        gettimeofday(&end, NULL);
        timer = 1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec;
        cout << timer / 1000 << "毫秒" << endl;
        cout << "**************" << endl;
    }
    return 0;
}